/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itsc.ds2.Dao;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.itsc.ds2.model.User;

/**
 *
 * @author Martinez
 */
@Stateless
public class UserDao extends AbstractDao<User> implements UserDaoLocal {
    @PersistenceContext(unitName = "MusicSchoolStudentControl-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UserDao() {
        super(User.class);
    }

    @Override
    public Boolean findByDuplicity(User user) {
        Query q = em.createNamedQuery("User.findByDuplicity");
        q.setParameter("id", user.getId());
        q.setParameter("accesId", user.getAccesId());
        return !q.getResultList().isEmpty();
    }

    @Override
    public List<User> findByUser(User user) {
        Query q = em.createNamedQuery("User.findById");
        q.setParameter("id", user.getId());
        return q.getResultList();
    }
    
    
}
